#ifndef MY_ACTION_H
#define MY_ACTION_H

#include <vector>

#include "action.h"
#include "cursor.h"
#include "trace.h"

using namespace std;

class PolygonAction : public Action{
    private:
        vector<Cursor> vertices;
        vector<Trace> edges;
        
        Scene *scene;
        
    public:
        PolygonAction(){}
        ~PolygonAction(){}
        
        void setScene(Scene* _scene){
            this->scene = _scene;
        }
        
        void setVertices(vector<Cursor> _vertices){
            this->vertices = _vertices;
        }

        void setEdges(vector<Trace> _edges){
            this->edges = _edges;
        }

        void act(Sketch& sketch){
            map<int, Trace>& traces = sketch.getTraces();
                        
            traces.clear();
            for (int k = 0; k < edges.size(); k++){
                traces[edges[k].getId()] = edges[k];
            }
            
            vector<Point> points;
            Point v1, v2;
            for (int z = 0; z < vertices.size()-1; z++){
                v1 = vertices[z].getScenePoint();
                v2 = vertices[(z+1)%vertices.size()].getScenePoint();
                scene->removeSegment( Segment( v1, v2) );
                
                points.push_back(vertices[z].getScenePoint());
                this->scene->addLine(v1, v2);
            }
            
            this->scene->addPolygon(points);
        }
};

#endif /* MY_ACTION_H */
